package com.zhaoyh.controller;

import com.zhaoyh.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.UUID;

/**
 * @author 祥霸
 * @date 2019/2/19
 */
@Controller
@RequestMapping(value = "/equipment")
public class EquipmentController extends BaseController{

    @Autowired
    EquipmentService equipmentService;

    /**
     * 获取编号
     * @author 祥霸
     * @date 2019/2/19
     * @parame [response]
     * @return void
     */
    @RequestMapping(value = "/no", method = RequestMethod.GET)
    public void getNo(HttpServletResponse response) {
        try {
            String uuid = UUID.randomUUID().toString().replace("-", "");

            // 添加到数据库
            String msg = equipmentService.insertEquipment(uuid, new Date(), 0, 0);

            System.out.println("getNo, " + uuid);

            renderData(response, uuid);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
